{% macro render_form(title, form, url, file_url, upload=False, col_md=True, img_sm=False) %}
<div class="{% if col_md %} col_md-form {% else %} form {% endif %}">
    <h1>{{ title }}</h1>
    <form method="POST" enctype="{% if upload %}multipart/form-data{% endif %}" action="{{ url }}">
        {{ form.csrf_token }}
        {% for field in form %}
            {% if field.type == "CSRFTokenField" %}
                {{ "" }}
            {% elif field.type == "SubmitField" %}
                {{ form.submit(class="btn btn-primary center-block submit_btn", type="submit") }}
            {% elif field.type == "BooleanField" %}
                <div class="checkbox">
                    <label>{{ field() }} {{ field.label.text }}</label>
                </div>
            {% elif field.type == "FileField" %}
                <label>{{ field.label }}</label>
                    {% if file_url %}
                        {% if img_sm %}
                        <br><img src="{{ file_url }}" class="logo-img">
                        {% else %}
                        <br><img src="{{ file_url }}">
                        {% endif %}
                    {% endif %}
                <div style="margin-bottom: 16px">{{ field() }}</div>
                {% for error in field.errors %}
                    <span class="help-block" style="color: #fd5f39">{{ error }}</span>
                {% endfor %}
            {% else %}
                <div class="form-group {% if field.errors %}has-error{% endif %}">
                    {{ field.label }}
                    {% if field.flags.required %}
                        <span style="color: #fd5f39"> *</span>
                    {% endif %}
                    {{ field(class="form-control") }}
                    {% if field.errors %}
                        {% for error in field.errors %}
                            <div class="help-block">{{ error }}</div>
                        {% endfor %}
                    {% endif %}
                </div>
            {% endif %}
        {% endfor %}
    </form>
</div>
{% endmacro %}


{% macro render_pagination(pagination, endpoint, kw=None) %}
{% if pagination.pages > 1 %}
<nav class="nav-pagination" aria-label="Page navigation">
  <ul class="pagination">
    {% if pagination.has_prev %}
        <li><a href="{{url_for(endpoint, page=pagination.prev_num)}}">&laquo;</a></li>
    {% endif %}
      {% for page in pagination.iter_pages() %}
        {% if page %}
          {% if page != pagination.page %}
          <li><a href="{{ url_for(endpoint, page=page, kw=kw) }}">{{ page }}</a></li>
          {% else %}
          <li class="active"><a class="disabled">{{page}} <span class="sr-only">(current)</span></a></li>
          {% endif %}
        {% endif %}
      {% endfor %}
    {% if pagination.has_next %}
        <li><a href="{{url_for(endpoint, page=pagination.next_num)}}">&raquo;</a>  </li>
    {% endif %}
  </ul>
</nav>
{% endif %}
{% endmacro %}


{% macro render_company(company) %}
<div class="col-sm-6 col-md-3 company-item">
  <div class="thumbnail">
      <a href="{{ url_for('company.detail', company_id=company.id) }}">
          <img class="img-rounded logo-img" src="{{ company.logo }}" alt="{{ company.name }}">
      </a>
      <h4><a href="{{ url_for('company.detail', company_id=company.id) }}">{{ company.name  | truncate(6, True)}}</a></h4>
      <p>{{ company.field }} / {{ company.finance_stage }}</p>
  <hr>
  <a href="{{ url_for('company.detail', company_id=company.id, job='job') }}">
      <p style="padding-bottom: 10px">
         {{ company.enabled_jobs().count() }}<br/>在招职位
      </p>
  </a>
  </div>
</div>
{% endmacro %}


{% macro render_job(job) %}
<div class="col-sm-6 col-md-4">
  <div class="job-box">
      <div class="caption">
        <a href="{{ url_for('job.detail', job_id=job.id) }}">
        <b>{{ job.name | truncate(10, True)}}</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </a><br/>
        <span style="font-size: 13px">{{ job.city }} / {{ job.exp }}经验 / {{ job.education }}</span>
          <span class="salary" style="font-size: 16px; float: right; margin-right: 12px">{{ job.salary_min }}k-{{ job.salary_max }}k</span><br/>
          {% if job.tag_list %}
            {% for tag in job.tag_list[:2] %}
              <span class="index-label"><small>{{ tag }}</small></span>
            {% endfor %}
          {% endif %}
        <span>&nbsp;</span>
      </div>
      <hr>
      <div class="media">
        <div class="media-left">
          <a href="{{ url_for('company.detail', company_id=job.company.id) }}">
            <img class="img-rounded media-object" src="{{ job.company.logo }}" width="60" height="60" alt="job.company.name">
          </a>
        </div>
        <div class="media-body">
          <a href="{{ url_for('company.detail', company_id=job.company.id) }}">
          <h4 class="media-heading">{{ job.company.name  | truncate(6, True) }}</h4>
          </a>
          <span class="company-meta">{{ job.company.field }} / {{ job.company.finance_stage }}</span>
          </div>
        </div>
    </div>
</div>
{% endmacro %}


{%- macro render_search(endpoint) -%}
  {% call form_tag(endpoint, method='get') %}
    <label for="q"></label>
    <div class="input-group md-margin-bottom">
      <input type="text" class="form-control"
             id="q" name="q" value="{{ request.args.get('q', '') }}"
             placeholder="Search by typing, then press enter...">
    <span class="input-group-addon">
      <i class="fa fa-fw fa-search"></i>
    </span>
    </div>
  {% endcall %}
{%- endmacro -%}